package com.mapbased.wfw.components;

import java.io.*;
import java.util.*;

import org.dom4j.*;
import com.mapbased.wfw.*;
import com.mapbased.wfw.PageLoader.StringBufferBag;

/**
 *
 * <p>Title: </p>
 *
 * <p>Description:remove html tags ,while to export javascript </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class RemoveTag
    extends Component
{

  /**
   *
   * @param ele Element
   * @param loader PageLoader
   * @return Element or null:if wanna page loader parse the
   *   component,return the ele, else return null
   * @todo Implement this com.mapbased.wfw.Component method
   */
  public Element parseXml(Element ele,PageLoader.LoadContext lc)
  {
    lc.loader.parseElementChildren(ele,lc);
    return null;
  }

  Element old_parseXml(Element ele,PageLoader.LoadContext lc)
  {
    //  String s=ele.getText();
    PageLoader.LoadContext nlc = new PageLoader.LoadContext(lc);
    java.util.List segs = nlc.segments;
    StringBufferBag last = nlc.last;
    //    PageLoader.parseBinding(s,segs,last);

    for (int i = 0;i < ele.nodeCount();i++)
    {
      Node n = ele.node(i);
      switch (n.getNodeType())
      {
        case Node.ELEMENT_NODE:
          lc.loader.parseElement((Element) n,nlc);

          break;

        case Node.NAMESPACE_NODE:

        case Node.ATTRIBUTE_NODE:
          break;

        case Node.CDATA_SECTION_NODE:
        case Node.COMMENT_NODE:

        case Node.PROCESSING_INSTRUCTION_NODE:
          last.buffer.append(" ").append(n.asXML());
          break;

        case Node.TEXT_NODE:

          //Text t=(Text)n;
          lc.loader.parseBinding(n.getText(),lc);
          break;

      }
    }

    if (last.buffer.length() > 0)
    {
      segs.add(last.getString());
    }

    this.setSegments(segs.toArray());

    return null;
  }

  /**
   * render
   *
   * @param context RenderContext
   * @throws IOException
   * @todo Implement this com.mapbased.wfw.Component method
   */
  public void render(RenderContext context)
      throws IOException
  {
    this.defalutRenderBehavior(context);
  }

  /**
   * renderHeader
   *
   * @param context RenderContext
   * @param sb StringBuffer
   * @param m Map
   * @todo Implement this com.mapbased.wfw.Component method
   */
  public void renderHeader(RenderContext context,StringBuffer sb,Map m)
  {
  }
}
